home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1996 September
/
JCSM Shareware Collection (JCS Distribution) (September 1996).ISO
/
bother__
/
cenvid.zip
/
CENVIDOS.ZIP
/
WINCLIP.LIB
< prev
next >
Wrap
Text File
|
1995-03-28
|
9KB
|
273 lines
// WinClip.lib - Functions for reading from and writing
// ver.1 to the Windows clipboard from DOS.
//
//**** GetClipboardText() Read text string from Windows clipboard
// SYNTAX: string GetClipboardText()
// RETURN: NULL if cannot find or retrieve clipboard text, else return
// null-terminated string of clipboard data
//
//
//**** PutClipboardText() Write text string to the Windows clipboard
// SYNTAX: bool PutClipboardText(string Text)
// WHERE: Text: null-terminated string to write to clipboard; or NULL
// to delete the contents of the clipboard
//
if !defined(_DOS_)
printf("\n\a\aWinClip must execute from CEnviD for DOS.\n"),
exit(EXIT_FAILURE);
ClipboardAvailable() // return True if functions available, else False
{
RegIn.ax = 0x1700;
interrupt(0x2f,RegIn,RegOut);
if ( RegOut.ax == 0x1700 ) {
printf("\nClipboard functions not available\n");
return False;
}
return True;
}
OpenClipboard() // return True for success, else False
{
RegIn.ax = 0x1701;
interrupt(0x2F,RegIn,RegOut);
if ( RegOut.ax == 0 ) {
printf("\nUnable to open clipboard.\n");
return False;
}
return True;
}
CloseClipboard() // return True for success, else False
{
RegIn.ax = 0x1708;
interrupt(0x2F,RegIn,RegOut);
if ( RegOut.ax == 0 ) {
printf("\nUnable to open clipboard.\n");
return False;
}
return True;
}
GetClipboardDataSize(pType) // return size of data in clipboard; 0 if none
{
RegIn.ax = 0x1704;
RegIn.dx = pType;
interrupt(0x2F,RegIn,RegOut);
return ( RegOut.ax | (RegOut.dx << 16) );
}
GetClipboardData(pBuf,pType) // assume that pBuf is big enough
{
RegIn.ax = 0x1705;
RegIn.dx = pType;
RegIn.es = segment(pBuf); RegIn.bx = offset(pBuf);
interrupt(0x2F,RegIn,RegOut);
if ( 0 == RegOut.ax ) {
printf("\nError on GetClipboardData\n");
return False;
}
return True;
}
GetClipboardText()
{
lText = NULL; // assume failure
if ( ClipboardAvailable() && OpenClipboard() ) {
if ( lClipboardSize = GetClipboardDataSize(1) ) {
undefine(lText);
lText[lClipboardSize] = '\0';
if ( !GetClipboardData(lText,1) )
lText = NULL;
else
SetArraySpan(lText,strlen(lText));
}
CloseClipboard();
}
return lText;
}
EmptyClipboard()
{
RegIn.ax = 0x1702;
interrupt(0x2F,RegIn,RegOut);
if ( RegOut.ax == 0 ) {
printf("\Error on EmptyClipboard()\n");
return False;
}
return True;
}
ClipboardCompact(pSize)
{
RegIn.ax = 0x1702;
RegIn.si = (pSize >> 16 & 0xFFFF); RegIn.cx = pSize & 0xFFFF;
interrupt(0x2F,RegIn,RegOut);
return ( RegOut.ax | (RegOut.dx << 16) );
}
SetClipboardData(pBuf,pBufSize,pType)
{
RegIn.ax = 0x1703;
RegIn.dx = pType;
RegIn.es = segment(pBuf); RegIn.bx = offset(pBuf);
RegIn.si = (pBufSize >> 16 & 0xFFFF); RegIn.cx = pBufSize & 0xFFFF;
interrupt(0x2F,RegIn,RegOut);
if ( RegOut.ax == 0 ) {
printf("\Error on SetClipboardData()\n");
return False;
}
return True;
}
PutClipboardText(pText)
{
lSuccess = False; // assume failure
if ( ClipboardAvailable() && OpenClipboard() ) {
if ( EmptyClipboard() ) {
if ( !pText ) {
lSuccess = True;
} else {
lTextLen = strlen(pText);
if ( ClipboardCompact(lTextLen+1)
&& SetClipboardData(pText,lTextLen+1,1) ) {
lSuccess = True;
}
}
}
CloseClipboard();
}
return lSuccess;
}
//Parameters AX = 1704H
// DX = WinOldAp-Supported Clipboard format
//Return Values DX:AX == Size of the data in bytes, including any
// headers.
// == 0 If data in this format is not in the clipboard.
//
//Name IdentifyWinOldApVersion()
//Parameters AX = 1700H
//Return Values AX == 1700H: Clipboard functions not available
// <> 1700H: AL = Major version number
// AH = Minor version number
//
//Name OpenClipboard()
//Parameters AX = 1701H
//Return Values AX == 0: Clipboard already open
// <> 0: Clipboard opened
//
//Name EmptyClipboard()
//Parameters AX = 1702H
//Return Values AX == 0: Error occurred
// <> 0: OK, Clipboard emptied
//
//Name SetClipboardData()
//Parameters AX = 1703H
// DX = WinOldAp-Supported Clipboard format
// ES:BX = Pointer to data
// SI:CX = Size of data in bytes
//Return Values AX == 0: Error occurred
// <> 0: OK. Data copied into allocated memory.
//Note The MS-DOS application should call the
// ClipboardCompact() function prior to this to determine
// if the data can be accommodated in memory.
//
//Name GetClipboardDataSize()
//Parameters AX = 1704H
// DX = WinOldAp-Supported Clipboard format
//Return Values DX:AX == Size of the data in bytes, including any
// headers.
// == 0 If data in this format is not in the clipboard.
//
//Name GetClipboardData()
//Parameters AX = 1705H
// DX = WinOldAp-Supported Clipboard format
// ES:BX = Pointer to data buffer to hold data
//Return Values AX == 0: Error occurred (or data in this format is not
// in the clipboard)
// <> 0: OK
//Note This call should be preceded by a
// GetClipBoardDataSize() call to find out how much memory
// is required for the buffer. No checking is performed, the
//
// caller must ensure that the buffer is big enough;
// otherwise, some of the callers code or data may be
// overwritten.
//
//Name CloseClipboard()
//Parameters AX = 1708H
//Return Values AX == 0: Error occurred
// <> 0: OK
//
//
//Name ClipboardCompact()
//Parameters AX = 1709H
// SI:CX = Desired memory size in bytes.
//Return Values DX:AX == Number of bytes of largest block of free memory.
// == 0 if error or no memory
//Notes The MS-DOS application is responsible for including the
// size of any headers in the desired memory size.
//
//
//
//Name GetDeviceCaps()
//Parameters AX = 170AH
// DX = GDI information index
//Return Values AX == integer value of desired item
// == 0 if error
//Notes The implied hDC for this call will be for the display.
//
//
//
//Supported Clipboard Formats
//---------------------------
//
//
//
//The following Windows clipboard formats are supported:
//
//
//
// CF_TEXT = 1
// CF_BITMAP = 2 ; See structures section
// CF_OEMTEXT = 7
// CF_DSPTEXT = 81h
// CF_DSPBITMAP = 82h
//Note: Since the RegisterClipboardFormat() and EnumClipboardFormats()
// functions are not available at this time, the use of private
// clipboard formats is not supported.
//Structures
//----------
//
//
//
//These structures mimic the actual Windows structures with one major
//difference: instead of including a handle or pointer to other memory
//containing the actual data, the data follows the structure. The
//structure information now behaves like a header prefacing the data.
//
//
//
//Bitmap structure:
//
//
//
// bmType DW ? ; Always 0
// bmWidth DW ? ; Width of bitmap in pixels
// bmHeight DW ? ; Height of bitmap in raster lines
// bmWidthBytes DW ? ; Bytes/raster line
// bmPlanes DB ? ; Number of color planes in the bitmap
// bmBitsPixel DB ? ; Number of adj color bits to def pixel
// bmBits DQ ? ; Points to byte following bmHigDim
// bmWidDim DW ? ; Width of bitmap in 0.1 mm units
//
// bmHigDim DW ? ; Height of bitmap in 0.1 mm units
// BitmapData nBytes ; The actual data
//
//
//
//#:x218a
//